﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;

namespace Devsoft.Utilities
{
    public class NetUtil
    {
        public static string GetEnthernetIp()
        {
            IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties();
            NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
            PhysicalAddress address =
                nics.Where(adapter => adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet).Select(
                    x => x.GetPhysicalAddress()).FirstOrDefault() ??
                nics.Where(adapter => adapter.NetworkInterfaceType == NetworkInterfaceType.Wireless80211).Select(
                        x => x.GetPhysicalAddress()).FirstOrDefault();

            return string.Join(".", address.GetAddressBytes().Select(x => x.ToString("X2")));
        }
    }
}
